package com.doradance.net;


import com.yong.android.framework.utils.log.SLog;

import io.reactivex.Observer;

/**
 * Description:
 * Created by Andy Hong on 10/19/2017.
 */

public abstract class ServerTaskObserver<T> implements Observer<T> {


    public abstract void onSuccess(T value);

    public abstract void onFailure(FailureBean failureBean);


    @Override
    public final void onNext(T value) {
        onSuccess(value);
    }

    @Override
    public final void onError(Throwable e) {
        FailureBean failureBean = new FailureBean(e);
        if (!failureBean.isServerFailure()) {
            SLog.e("onError",e.getMessage());
            e.printStackTrace();
        } else {
            SLog.e(failureBean.getServerFailureBean().toString());
        }
        onFailure(failureBean);
    }

    @Override
    public final void onComplete() {
    }
}
